<?php
    class FilePresentation {
        function __construct() {
        }
        
        function Update($ItemImageFile,$dirname) {
            print "
                  <form name=\"DEL_IMG$ItemImageFile->fileName\" action=\"MainAdminWnd.php\" method=\"POST\" enctype=\"multipart/form-data\">
                  <img src=\"../../../data/photoalbums/$dirname/$ItemImageFile->fileName\" width=\"100\" height=\"100\"/>
                  <br>
                  <input type=\"submit\" value=\"Zmazať\" name=\"DEL$ItemImageFile->fileName\" />
                  <input type=\"hidden\"  name=\"FILE\" value=\"$ItemImageFile->fileName\" />
                  <input type=\"hidden\"  name=\"DIRNAME\" value=\"$dirname\" />
                  <input type=\"hidden\"  name=\"ACTION\" value=\"DELETE\" />
                  </form>
                  <form name=\"SAVE_IMG$ItemImageFile->fileName\" action=\"MainAdminWnd.php\" method=\"POST\" enctype=\"multipart/form-data\">
                  <table><tr><td>
                      Názov: </td><td> <input type=\"text\" name=\"NAME\" value=\"$ItemImageFile->name\" /> 
                        </td></tr><tr><td>
                      Popis: </td><td> <textarea name=\"DESCRIPTION\" rows=\"4\" cols=\"20\" />$ItemImageFile->description</textarea>
                  </td></tr></table>
                  <input type=\"submit\" value=\"Uložiť\" name=\"SAVE$ItemImageFile->fileName\" />
                  <input type=\"hidden\"  name=\"FILE\" value=\"$ItemImageFile->fileName\" />
                  <input type=\"hidden\"  name=\"DIRNAME\" value=\"$dirname\" />
                  <input type=\"hidden\"  name=\"ACTION\" value=\"UPDATE\" />
                  </form>
                  ";//<input type=\"text\" name=\"DESCRIPTION\" value=\"$ItemImageFile->description\" />
        }
        
        function Insert($dirname) {
            print "
                  <form name=\"INSERT_IMG\" action=\"MainAdminWnd.php\" method=\"POST\" enctype=\"multipart/form-data\">
                  Pridať obrázok :
                  <table><tr><td>
                      Obrázok: </td><td> <input type=\"file\" name=\"FILE_UPLOAD\" value=\"\" /> 
                        </td></tr><tr><td>
                      Názov: </td><td> <input type=\"text\" name=\"NAME\" value=\"\" /> 
                        </td></tr><tr><td>
                      Popis: </td><td> <textarea name=\"DESCRIPTION\" rows=\"4\" cols=\"20\" /></textarea>
                  </td></tr></table>
                  <input type=\"submit\" value=\"Vytvoriť\" name=\"INSERT\" />
                  <input type=\"hidden\"  name=\"ACTION\" value=\"INSERT\" />
                  <input type=\"hidden\"  name=\"DIRNAME\" value=\"$dirname\" />
                  </form>
                  <hr>
                  ";
        }
         
        function Grid($list,$dirName) {
            $i=1;
            $itemInRow = 3;
            $ColorArr = array("#D3D2D1","#AEACAB");
            $count = count($list);
            print"<table><tr>"; 
            foreach($list as $ItemImageFile)
                {
                    print"<td align=\"center\" bgcolor=\"".$ColorArr[($i+1)%2]."\">";
                    $this->Update($ItemImageFile,$dirName);
                    print"</td>";
                    if(!($i%$itemInRow)) print"</tr><tr>";
                    $i++;
                }
            print"</tr></table>";
        }
        
        function ReqDELETE() {
            if($_REQUEST["ACTION"]=="DELETE")
                return $_REQUEST["FILE"];
        }
        
        function ReqUPDATE() {
            if($_REQUEST["ACTION"]=="UPDATE")
            {
                $result = new ItemImageFile();
                $result->fileName = $_REQUEST["FILE"];
                $result->name =   $_REQUEST["NAME"];
                $result->description = $_REQUEST["DESCRIPTION"];
                return $result;
            }
            else
                return "";
        }
        
        function ReqINSERT(&$FileTMP) {
            if($_REQUEST["ACTION"]=="INSERT")
            {
                $FileTMP = $_FILES['FILE_UPLOAD']['tmp_name'];
                
                $result = new ItemImageFile();
                $result->fileName = $_FILES['FILE_UPLOAD']['name'];
                $result->name =   $_REQUEST["NAME"];
                $result->description = $_REQUEST["DESCRIPTION"];
                return $result;
            }
            else
                return "";
        }
        
        function __destruct() {
        }
    }
?>
